package com.guoqing.example.common;


/**
 * @author : Hejinsheng
 * @date Date : 2018年10月28日 16:01
 * @Description:
 */

/**
 * 后端统一返回类
 *
 * @param <T>
 */
public class Result<T> {

    private String code;

    private String message;

    private T data;

    private Boolean success;

    public Result() {
    }

    public Result(Boolean success, String code, String message, T data) {
        this.success = success;
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public Result(Boolean success, String code, String message) {
        this.success = success;
        this.code = code;
        this.message = message;
    }

    public Result(String code, String message) {
        this.code = code;
        this.message = message;
    }

    public static Result buildSuccess() {
        return new Result(Boolean.TRUE, MyEnum.SUCCESS.getCode(),
                MyEnum.SUCCESS.getMessage());
    }

    public static Result buildSuccess(Object data) {
        return new Result(Boolean.TRUE, MyEnum.SUCCESS.getCode(),
                MyEnum.SUCCESS.getMessage(), data);
    }

    public static Result buildFailed() {
        return new Result(Boolean.FALSE, MyEnum.FAILED.getCode(),
                MyEnum.FAILED.getMessage());
    }

    public static Result buildFailed(String code, String message) {
        return new Result(Boolean.FALSE, code, message);
    }

    public static Result buildFailed(MyEnum resultCode) {
        return new Result(Boolean.FALSE, resultCode.getCode(), resultCode.getMessage());
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public Boolean getSuccess() {
        return success;
    }

    public void setSuccess(Boolean success) {
        this.success = success;
    }
}
